﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


using PowerCreator.LMS.Question.Core;
using PowerCreator.LMS.Question.Entiry;
using System.Text;
using PowerCreator.LMS.Common.Script;


public partial class sysadmin_QuestionManager_QuestionResourceList : PowerCreator.LMS.Web.Base.BasePage
{
   
  
    ManagerQuestion objQuestion = new ManagerQuestion();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string search = GetSearch();
            BinderPager(search);
            BinderGV(search, 1);
            InitPage();
        }
    }
    protected override void InitPage()
    {
        base.InitPage();
    }
    private string GetSearch()
    {
        string search = string.Format(" QuestionResFileName like '%{0}%'", txt_Resourcename.Text.Trim());
        return search.ToString();
        
    }
    private void BinderPager(string search)
    {
        AspNetPager1.RecordCount = objQuestion.CountQuestionResource(search);
        AspNetPager1.PageSize = LMSPageSize;
    }

    private void BinderGV(string search, int pageIndex)
    {
        DataTable dt = new DataTable();

        dt = objQuestion.QueryQuestionResource(search, LMSPageSize, pageIndex);
        dt.Columns.Add("index");
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            dt.Rows[i]["index"] = i + 1;
        }
        gvQuestionList.DataSource = dt;
        gvQuestionList.DataBind();
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderPager(search);
        BinderGV(search, 1);
    }
    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        string url = "AddQuestionType.aspx";
        Script.RedirectURL(url);
    }
    protected void gvQuestionList_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        //if (e.CommandName == "mydelete")
        //{
        //    //不能删除
        //    //string msg=manager.Delete(int.Parse(e.CommandArgument.ToString()));
        //    //Script.Alert(msg);
        //    //string search = GetSearch();
        //    //BinderPager(search);
        //    //BinderGV(search, 1);
        //}
        //if (e.CommandName == "myeditor")
        //{
        //    string url = "EditQuestionResource.aspx?ID=" + Base64.Encode(e.CommandArgument.ToString());
        //    Script.RedirectURL(url);
        //}
    }
    protected void gvQuestionList_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("bgColor", "#F7FAFF");
            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#FAEDB8'");
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#F7FAFF'");

            if (e.Row.Cells[5].Text.Trim() == "1")
            {
                e.Row.Cells[5].Text = "音视频";
            }
            else
            {
                e.Row.Cells[5].Text = "其他类型";
            }
        }
    }

    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        string search = GetSearch();
        BinderGV(search, AspNetPager1.CurrentPageIndex);
    }
    protected void btn_AddQuestion_Click(object sender, EventArgs e)
    {
        Script.RedirectURL("AddQuestionResource.aspx");
    }
}
